<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class SeedDataToAreasTable extends Migration
{
    public function up()
    {
        $region = DB::table('areas')->whereIn('id', [1, 18, 790, 2236, 3609, 3628])->get();

        foreach ($region as $v) {
            $city = DB::table('areas')->insertGetId([
                'parent_id' => $v->id,
                'name'      => $v->name,
                'type'      => 2,
                'code'      => $v->code,
            ]);

            DB::table('areas')->where('id', '<>', $city)->where(['parent_id' => $v->id, 'type' => 2])->update([
                'parent_id' => $city,
                'type'      => 3,
            ]);
        }
    }

    public function down()
    {

    }
}
